package com.carsystems.controller;

import com.carsystems.mapper.NoticeMapper;
import com.carsystems.pojo.Notice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class NoticeController {
    @Autowired
    private NoticeMapper noticeMapper;


    //查询全部通知列表
    @GetMapping("/noticeList")
    public List<Notice> NoticeList(){
        List<Notice> notices = noticeMapper.NoticeList();
        return notices;
    }

    //按id查询通知
    @GetMapping("/noticeid")
    public Notice noticeid(Integer tz_id){
        return noticeMapper.selectByPrimaryKey(tz_id);
    }

    //添加一条通知
    @ResponseBody
    @PostMapping("/addNotice")
    public  String addNotice(@RequestBody Notice notice){
        noticeMapper.addNotice(notice);
        if (notice != null){
            return "success";
        }else {
            return "fail";
        }
    }

    //修改一条通知内容
    @ResponseBody
    @PostMapping("/updateNotice")
    public String updateNotice(@RequestBody Notice notice){
       int row =  noticeMapper.updateNotice(notice);
        noticeMapper.selectByPrimaryKey(notice.getTz_id());
        if (row == 1){
            return "success";
        }else {
            return "fail";
        }
    }

    //删除一条通知
    @ResponseBody
    @GetMapping("/deleNotice")
    public String deleNotice( Notice noticeid){
       int row = noticeMapper.daleteNotice(noticeid.getTz_id());
       if (row ==1){
           return "success";
       }else {
           return "fail";
       }
    }
}
